home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Light ROM Gold
/
Light ROM Gold.iso
/
arexx
/
movscn32.rex
< prev
next >
Wrap
OS/2 REXX Batch file
|
1995-08-11
|
25KB
|
807 lines
/* CMD: Move Scene v3.2
* Move Lightwave Scene file and all that it is used in it, to a new
* place. Useful for transfering scenes to another computer.
* It will move all of your images, rearrange your scene file so
* that the objects will load from the new directory you specified.
* It will also take into account if you are moving your scenes into
* 3.5" disks and measure how much space is left, requesting new
* disks and initialize them in Amiga or IBM format.
*
* To run the macro, you will need these Workbench programs in C:
* copy, makedir, list, delete, format, info and rename.
*
* To use PC disks, you should have CrossDos (included in WB 2.1+) and
* installed for your internal drive (DF0).
*
* If using lha, you should have lha - if you prefer another lha
* compressor, just use your favorite editor to change the LHA_C
* variable path to the compressor you like.
* You could probably modify LHA to work with ARJ, or other PC compressor.
*
* If using compress, you should also have compress.b16 in C:.
*
* NOTE: This version 3.2 is still beta. The reason I decided to
* release it was that many people seemed to need it.
* In this version, if you use any type of compression, you
* will not be able to load the file into LW later. You will
* have to rename all the files. This might be fixed later.
* Also, this macro assumes all your images are saved as IFF.
* If not, change the IFF_EXT variable to what you like.
* Video Toaster image files are not supported.
* Bugs, comments and suggestions to ggarramuno@sicoar1.satlink.net
*
* 8/94 Version 1.0 - By Gonzalo Garramuno (C) 1994
* 11/94 Version 2.0 - By Gonzalo Garramuno (C) 1994
* > fixed bug with objects bigger than 65,535 bytes.
* > added option to turn off copying image and
* image sequences.
* > added option for changing the paths of the
* scene and object files to point to the new
* place.
* > added option for multiple disks, formatting
* them as needed.
* > added lha compression if lha is in C:
* note: if using lha, avoid files with bad
* names (ie. those that have wildcards
* characters in them, such as ?,#,),etc)
*
* 3/95 Version 3.0 (C) 1995 Gonzalo Garramuno
* > added shortening files to 8 characters.
* > added manual rename of files to 8 chrs. when
* automatic will not work.
* > changing spaces to underscores.
* > added compress compression for SGI compatibility.
* watch out for wrong characters: !, etc.
* > added changing of slashes.
* 4/95 Version 3.1 > added moving to remote directory.
* 7/95 Version 3.2 > corrected extensions to LWS, LWO and IFF
* (Can be modified easily, if needed).
* > corrected silly bug when moving an scene NOT to
* a remote directory.
*/
/* Extensions Variables */
SCENE_EXT = "LWS"
OBJECT_EXT = "LWO"
IFF_EXT = "IFF"
/* Compression commands */
LHA_C = "LHA"
COMP_C = "compress.b16"
call addlib "LWModelerARexx.port", 0
call addlib "rexxsupport.library", 0, -30, 0
signal on error
signal on syntax
sysnam = 'Move Scene'
version = 'Move Scene v3.2'
statfil="T:move.scene"
image = 3
path = 1
disk = 1
dnum = 1
comp = 1
short = 0
repl = 0
slash = 0
rem = 0
remname = ""
cant = 0
nfil = 0
if (exists(statfil)) then do
if (~open(state, statfil, 'R')) then break
if (readln(state) ~= version) then break
l1 = readln(state)
l2 = readln(state)
image = readln(state)
path = readln(state)
disk = readln(state)
comp = readln(state)
short = readln(state)
repl = readln(state)
slash = readln(state)
rem = readln(state)
remname = readln(state)
call close state
end
if l1="L1" then do
/* If you have Lightwave installed somewhere else other than
Toaster: then change the path below */
l1="Toaster:3D/Scenes"
name1=""
l2="ram:"
name2=""
end
else do
filenam="/"
s=2
if lastpos("/",l1)=0 then do
filenam=":"
s=1
end
name1=right(l1,length(l1)-lastpos(filenam,l1))
l1=left(l1,pos(name1,l1)-s)
filenam="/"
s=2
if lastpos("/",l2)=0 then do
filenam=":"
s=1
end
if length(l2)=lastpos(filenam,l2) then filenam=""
name2=right(l2,length(l2)-lastpos(filenam,l2))
l2=left(l2,pos(name2,l2)-s)
end
filenam=getfilename("-- Lightwave Scene --",l1,name1)
if filenam ="(none)" then exit
call REQ_BEGIN("Move Scene")
id_disk=REQ_ADDCONTROL("Copy to?",'CH',"Directory",
"Multiple"d2c(160)"DF0: Multiple"d2c(160)"PC0:")
id_image=REQ_ADDCONTROL("Copy Images?",'CH',"No Images"d2c(160)"only
Images"d2c(160)"and"d2c(160)"Sequences")
id_path=REQ_ADDCONTROL("Change Paths",'B')
id_comp=REQ_ADDCONTROL("Compression",'CH',"None LHA Compress")
id_short=REQ_ADDCONTROL("Shorten filenames to 8 chrs?",'B')
id_repl=REQ_ADDCONTROL("Change spaces to underscores?",'B')
id_slash=REQ_ADDCONTROL("Change / to \?",'B')
id_remote=REQ_ADDCONTROL("Use a remote directory?",'B')
id_remname=REQ_ADDCONTROL("Name of Remote Dir (add : or /)",'S')
call REQ_SETVAL(id_disk,disk)
call REQ_SETVAL(id_image,image)
call REQ_SETVAL(id_path,path)
call REQ_SETVAL(id_comp,comp)
call REQ_SETVAL(id_short,short)
call REQ_SETVAL(id_repl,repl)
call REQ_SETVAL(id_slash,slash)
call REQ_SETVAL(id_remote,rem)
call REQ_SETVAL(id_remname,remname)
ok=REQ_POST()
If ok~=1 Then exit
disk = REQ_GETVAL(id_disk)
image = REQ_GETVAL(id_image)
path = REQ_GETVAL(id_path)
comp = REQ_GETVAL(id_comp)
short = REQ_GETVAL(id_short)
repl = REQ_GETVAL(id_repl)
slash = REQ_GETVAL(id_slash)
rem = REQ_GETVAL(id_remote)
remname = REQ_GETVAL(id_remname)
select
when disk=1 then do
Drawer=getfilename("-- Drawer to Create --",l2,name2)
if Drawer ="(none)" then exit
Drawer = short(Drawer,"")
end
when disk=2 then Drawer="DF0:"
otherwise Drawer="PC0:"
end
remDraw = Drawer || "/"
if rem = 1 then remDraw = remname
/* Save preferences just in case */
if (open(state, statfil, 'W')) then do
call writeln state, version
call writeln state, filenam
call writeln state, Drawer
call writeln state, image
call writeln state, path
call writeln state, disk
call writeln state, comp
call writeln state, short
call writeln state, repl
call writeln state, slash
call writeln state, rem
call writeln state, remname
call close state
end
if disk>1 then call askdisk()
if comp = 2 then Drawer = Drawer || ".lha"
if comp = 3 then Drawer = Drawer || ".Z"
/* Number of Images in Scene and/or Objects */
img=0
if (exists(filenam)) then do
/* Erase if there was a previous one by mistake */
address command
if (disk=1)&(exists(Drawer)) then do
if notify(2,"Delete "||Drawer"?")=0 then exit
'delete "'Drawer'" all >NIL:'
end
obj=0
if (~open(state, filenam, 'R')) then exit
parse value readln(state) with type .
if type~="LWSC" then do
Bummer("Not a Lightwave ASCII Scene!")
end
else do while eof(state)=0
type=readln(state)
if left(type,11)="LoadObject " then do
obj=obj+1
object.obj = substr(type,12)
newobj.obj = short(object.obj,OBJECT_EXT)
end
/* Handle images in scene file
* Background, Foreground, Alpha, Displacement and Clip maps */
if image > 1 then do
l=pos(" ",type)
if l=0 then l=1
if (left(type,l)="BGImage "),
|(left(type,l)="FGImage "),
|(left(type,l)="FGAlphaImage "),
|(left(type,l)="TextureImage ") then do
img = img + 1
image.img = substr(type,l+1)
newimg.img = short(image.img,IFF_EXT)
end
end
end
call close state
/* Make dir and copy scene file to it */
if disk=1 then call makdir(Drawer)
newnam = short(filenam,SCENE_EXT)
call cop(filenam,Drawer,newnam)
if disk=1 then Drawer=Drawer||"/"
/* Check repeated objects when shortening to 8 chrs */
if (short = 1) & (obj > 1) then do
do i = 2 to obj
do l = (i - 1) to 1 by -1
if (short(newobj.i) = short(newobj.l)),
& (newobj.i ~= newobj.l) then do
call REQ_BEGIN("Please manually shorten "GetName(object.i))
id_name=REQ_ADDCONTROL("Type New Name (8 chrs)","S",8)
ok=REQ_POST()
if ok = 0 then exit
type = search(newobj.i)
type = left(newobj.i,type)
newobj.i = short(type || REQ_GETVAL(id_name),OBJECT_EXT)
l = l + 1
end
end l
end i
end
/*****************************************/
/* Copy all objects to Objects Directory */
/*****************************************/
if obj>0 then do
call METER_BEGIN(obj+1,"Moving Objects")
call makdir(Drawer"Objects")
do i=1 to obj
call METER_STEP()
call cop(object.i,Drawer"Objects",newobj.i)
if image > 1 then do
if (~open(state, object.i, 'R')) then exit
seq=0
/* Type is an array, to avoid problems with big objects */
do while eof(state) = 0
seq = seq + 1
type.seq = readch(state,65535)
end
call close state
do t=1 to seq
l=0
l2=1
do while (l<length(type.t))&(length(type.t)>3)
/* Search for "IMG" in object, which tells us about an image file */
l = pos("IMG",type.t,l2)
if l ~= 0 then do
l2 = pos(d2c(0),type.t,l+4)
l2 = l2-l-5
check = 0
do s = 1 to img
if substr(type.t,l+5,l2)=image.s then check = 1
if substr(type.t,l+5,l2)="(none)" then check = 1
end s
if check=0 then do
img = img+1
image.img = substr(type.t,l+5,l2)
newimg.img = short(image.img,IFF_EXT)
end
l2 = l+l2
l = l2
end
else l = length(type.t)
end
end t
end
end i
end
call METER_END
/* Check repeated images when shortening to 8 chrs */
if (short = 1) & (img > 1) then do
do i = 2 to img
do l = (i - 1) to 1 by -1
if short(newimg.i) = short(newimg.l) then do
call REQ_BEGIN("Please manually shorten "GetName(image.i))
id_name=REQ_ADDCONTROL("Type New Name (8 chrs)","S",8)
ok=REQ_POST()
if ok = 0 then exit
type = search(newimg.i)
type = left(newimg.i,type)
newimg.i = short(type || REQ_GETVAL(id_name),IFF_EXT)
l = l + 1
end
end l
end i
end
/*******************************************************/
/* Copy all images (and sequences) to Images directory */
/*******************************************************/
if img>0 then do
call makdir(Drawer"Images")
call METER_BEGIN(img+1,"Moving Images")
call METER_STEP
do i = 1 to img
call METER_STEP
/* Handle sequences: create special dir */
if (right(image.i,11) = " (sequence)") then do
if image = 3 then do
name1 = short(CheckSeq(image.i),IFF_EXT)
name1 = left(name1,length(name1)-1)
image.i = left(image.i,length(image.i)-11)
call makdir(Drawer"Images/"||name1)
call cop(image.i"#?",Drawer"Images/"name1,newimg.i)
end
end
/* Handle image files */
else do
call cop(image.i,Drawer"Images",newimg.i)
end
end i
call METER_END
end
if path = 1 then do
name1=""
/***************************/
/* Modify Scene file paths */
/***************************/
if disk>1 then do
Drawer = "Disk"
call checkdisk2(files.1)
name1="1:"
end
l=search(filenam)
file=Drawer||name1||right(filenam,length(filenam)-l)
file=short(file,SCENE_EXT)
if (~open(state, filenam, 'R')) then break
if (~open(state2, file, 'W')) then break
do while eof(state)=0
type = readln(state)
if left(type,11)="LoadObject " then do
file = delstr(type,1,11)
l = search(file)
i = checkdisk(file)
type = "LoadObject " || remDraw || i || "Objects/"
name = short(right(file,length(file)-l),OBJECT_EXT)
type = type || name
end
if image > 1 then do
l = pos(" ",type)
if (left(type,l)="BGImage "),
|(left(type,l)="FGImage "),
|(left(type,l)="FGAlphaImage "),
|(left(type,l)="TextureImage ") then do
file = delstr(type,1,l)
if file~="(none)",
|((right(file,11)=" (sequence)")&(image=3)) then do
t=search(file)
dnum = checkdisk(file)
test = 8
name1 = short(CheckSeq(file))
if name1 ~= "" then test = 5
name = right(file,length(file)-t)
name = short(name,"",test)
file = remDraw || dnum || "Images/" || name1,
|| name
type = left(type,l) || file
end
end
end
if slash = 1 then type = translate(type,"\","/")
call writeln state2, type
end
call close state
call close state2
/***************************************/
/* Now modify the objects' images path */
/***************************************/
call METER_BEGIN(obj+1,"Modifying paths")
do i=1 to obj
call METER_STEP()
l = search(object.i)
t = checkdisk2(object.i)
file = Drawer || t || "Objects/"
name = short(right(object.i,length(object.i)-l),OBJECT_EXT)
file = file || name
if (~open(state, object.i, 'R')) then break
if (~open(state2, file, 'W')) then break
do while eof(state)=0
type = readch(state,10000)
l=0
l2=1
do while (l<length(type))&(length(type)>3)
l = pos("IMG",type,l2)
if l ~= 0 then do
l2 = pos(d2c(0),type,l+4)
l2 = l2-l-5
/* img = img+1 */
file = substr(type,l+5,l2)
if file~="(none)",
|((right(file,11)=" (sequence)")&(image=3)) then do
t=search(file)
dnum = checkdisk(file)
test = 8
name1 = short(CheckSeq(file))
if name1 ~= "" then test = 5
name = right(file,length(file)-t)
name = short(name,"",test)
file = remDraw || dnum || "Images/" || name1,
|| name
file = left(type,l+3)|| d2c(length(file)+2) || file
type = substr(type,l+l2+5)
end
else file = ""
type = file || type
l2 = l+l2
l = l2
end
else l = length(type)
end
if slash = 1 then type = translate(type,"\","/")
call writech state2, type
end
call close state
call close state2
end i
call METER_END()
end
file = SHOWLIST("V",,"|")
end
else do
Bummer("Can't open Scene file : "filenam)
end
exit
/* Ask to insert new disk */
askdisk: PROCEDURE EXPOSE dnum Drawer size obj img
t=notify(3,"@Please insert a new disk in DF0:",,
"!The disk will be formatted. All Information will be lost",,
"Are you sure you want to continue?")
if t=0 then exit
call METER_BEGIN(2,"Formatting disk")
call METER_STEP
address command
"format DRIVE" '"'Drawer'"' "NAME Disk"dnum "NOICONS >NIL:"
call METER_END()
if img>0 then call makdir(Drawer||"Images")
else do
if obj>0 then call makdir(Drawer||"Objects")
end
/* Get info on size of all disks */
"info >RAM:info.testfile "Drawer
/* Find the size of the disk we are working with */
if (~open(test, "RAM:info.testfile", 'R')) then break
do i=1 to 3
text = readln(test)
end i
text = readln(test)
text = word(text,2)
size = left(text,length(text)-1)*1000
call close test
"delete ram:info.testfile > NIL:"
return
/* Makedir procedure */
makdir: PROCEDURE
parse arg source
address command
if ~exists(source) then do
"makedir" '"'source'"'
end
return
/* Insert disk message */
insdisk: PROCEDURE EXPOSE Drawer
parse arg num
loop:
call notify(1,"Please insert Disk" num "in any drive")
/* Check that the user put the right disk in before going on */
Drives = SHOWLIST("V",,"|")
l = pos(UPPER(Drawer || num || "|"),Drives)
if l = 0 then call loop
return
/* Copy procedure. Checks for disk size */
Cop:
/* PROCEDURE EXPOSE disk Drawer cant size dnum obj img,
nfil files. fdisk. lha image */
parse arg source, dest, altsrc
if comp = 2 then do
source = lharc(source)
end
if comp = 3 then do
source = compress(source)
end
altsrc = GetName(altsrc)
if disk > 1 then do
add = 0
if (right(source,2) = "#?") then do
/* Get file size for all the images in sequence
* All the images of a sequence should fit in the same device.
*/
"list" source ">ram:info.testfile files quick lformat=%l"
if (~open(test, "RAM:info.testfile", 'R')) then break
do while eof(test)=0
text = readln(test)
if text~="" then add = add + text
end
call close test
"delete ram:info.testfile > NIL:"
end
else do
t = statef(source)
add = word(t,2)
end
if add > size then do
call notify(1,"You will not be able to fit the",,
"current scene on floppys. Use the Directory",,
"Option with a backup program or try compressing",,
"your objects before running the macro.")
exit
end
if (cant + add) > size then do
dnum = dnum + 1
cant = 0
call askdisk()
end
cant = cant + add
/* Add another file to list */
nfil = nfil + 1
files.nfil = source
fdisk.nfil = dnum
end
if right(source,2)="#?" then do
"list" source ">ram:info.testfile files quick lformat=%n"
t = statef("ram:info.testfile")
add = word(t,2)
if add = 0 then do
type = left(GetName(source),length(GetName(source))-2)
call notify(1,"The sequence "type" used in the",,
"scene is no longer in the same place",,
"or it has been deleted. Go into Layout",,
"and manually change the scene.")
"delete ram:info.testfile > NIL:"
exit
end
end
else if ~exists(source) then do
call notify(1,"The file "GetName(source)" used in the",,
"scene is no longer in the same place",,
"or it has been deleted. Go into Layout",,
"and manually change the scene.",,
"If it is an image, save all objects too.")
exit
end
address command
if right(source,2)="#?" then do
if (~open(test, "RAM:info.testfile", 'R')) then break
do while eof(test)=0
text = readln(test)
l = search(source)
if text ~= "" then do
t = pos("0",text)
altsrc = short(text,"",5)
if short = 1 then altsrc = altsrc || substr(text,t,3)
"copy" '"'left(source,l) || text'" "'dest'/'altsrc'"'
end
end
call close test
"delete ram:info.testfile > NIL:"
end
else do
"copy" '"'source'" "'dest'/'altsrc'" > NIL:'
end
/* Erase ram: .lha and .Z files */
if comp > 1 then 'delete "'source'" all >NIL:'
return
/* Find disk number for a file */
Checkdisk: PROCEDURE EXPOSE disk nfil files. fdisk. image
parse arg filenam
if disk = 1 then return ""
if (right(filenam,11) = " (sequence)")&(image=3) then do
filenam = left(filenam,length(filenam)-11)||"#?"
end
do i=1 to nfil
if filenam = files.i then return fdisk.i || ":"
end i
return
/* Check disk in drive to see if it is the one where file is.
* If not, ask for disk */
Checkdisk2: PROCEDURE EXPOSE disk nfil files. fdisk. Drawer
parse arg filenam
t = checkdisk(filenam)
if t = "" then return ""
t=left(t,1)
Drives = SHOWLIST("V",,"|")
l = pos(UPPER(Drawer || t || "|"),Drives)
if l = 0 then call insdisk(t)
t = t || ":"
return t
CheckSeq: PROCEDURE EXPOSE image
parse arg filenam
test = ""
if (right(filenam,11) = " (sequence)")&(image=3) then do
filenam = left(filenam,length(filenam)-11)
l = length(filenam) - search(filenam)
test = right(filenam,l) || "/"
end
return test
Search: PROCEDURE
parse arg filenam
i = lastpos("/",filenam)
l = lastpos(":",filenam)
if l>i then i=l
return i
/* Strip extensions and get name of file only */
GetName: PROCEDURE
parse arg name
l = search(name)
if n ~= 0 then do
name=right(name,length(name)-l)
end
return name
/* Compress files to ram: before copying them */
Lharc: PROCEDURE EXPOSE LHA_C
parse arg source
l = search(source)
file = "ram:" || right(source,length(source)-l)
LHA_C ' -x a "'file||'.lha"' '"'source'" >NIL:'
'rename "'file||'.lha"' '"'file'"'
return file
compress: PROCEDURE EXPOSE short repl COMP_C
parse arg source
l = search(source)
l2 = short
short = 1
file = short("ram:" || right(source,length(source)-l),"")
short = l2
'copy "'source'" "'file'"'
COMP_C' "'file'"'
file = file || ".Z"
return file
Short: PROCEDURE EXPOSE short repl
parse arg file, ext, l2
if right(file,2) = "#?" then file = left(file,length(file)-2)
seq = ""
if right(file,11)=" (sequence)" then do
file = left(file,length(file)-11)
seq =" (sequence)"
end
l = search(file)
if (l2 = " ") then l2 = 8
if (l + l2) > length(file) then l2 = length(file) - l
if repl = 1 then file = translate(file,"_-"," .")
if ext ~= "" then ext = "." || ext
if short = 1 then file = left(file,l) || substr(file,l+1,l2) || ext
file = file || seq
return file
Bummer:
parse arg etxt
t=Notify(1,'!Rexx Script Error','@'ETxt)
exit
syntax:
error:
call end_all
t=Notify(1,'!Rexx Script Error','@'ErrorText(rc),'Line 'SIGL)
exit